package il.ac.tau.cvws.scrabblesidekick.client.engine.storage;

import java.io.IOException;

import il.ac.tau.cvws.scrabblesidekick.client.util.FileUtil;
import il.ac.tau.cvws.scrabblesidekick.shared.datatype.StorageDataKey;

/* Storage abstraction for the data keys curated by the server.
 * These keys uniquely identify calibrated applications.
 */
public class DataKeyStorage
{
	private static final String KEY_DIR  = "scrabble_sidekick";
	private static final String KEY_NAME = "key";
	
	/* Store the given key as the application key.
	 */
	public static void storeDataKey(StorageDataKey key) throws IOException
	{
		FileUtil.storeObject(key, KEY_DIR, KEY_NAME);
	}
	
	/* Retrieve the currently stored application key.
	 */
	public static StorageDataKey retrieveDataKey() throws IOException, ClassNotFoundException
	{
		return (StorageDataKey)FileUtil.getObject(KEY_DIR, KEY_NAME);
	}
}
